import React, { Component } from 'react'
import { connect } from 'dva';
import {
  Form,
  Button,
  Select,
  Table,
  Icon,
  Modal,
  Input,
  Spin
} from 'antd'
import styles from './index.less';
const FormItem = Form.Item;
const Search = Input.Search;
export class PopoutRelevance extends Component {
  state = {
    showModel1: false,
    showModel2: false,
    showModel3: false,
    showModel4: false,
    numberRadio: '1',
  }



  handleOpen = (type) => {
    this.props.form.setFields({ "businessName": "" })
    this.props.onFrom('')
    console.log(this.props.text.question) // 父组件表单的每行数据 
    this.setState({
      // 动态控制变量 加[就会把key当成变量'']
      [type]: true,
      showModel4: true
    })
    let a = this.props.text.question
    this.props.onSubmit({ a })
  }

  // 搜索问题
  handleChange = value => {
    console.log(value)

    this.props.onFromA(value)
    this.setState({
      numberRadio: value
    })
  };

  // 搜索内容
  handleChangeA = e => {
    console.log(e.target.value)
    this.props.onFrom(e.target.value)
  }

  // eslint-disable-next-line react/sort-comp
  onChangeA = (current) => { // 页数选择
    console.log(current)
    this.props.onSubmit({ current }) // 给父组件传值 实现更改数据
  }

  // 每页显示多少条数据
  onShowSizeChangeA = (current, pageSize) => {
    console.log(current, pageSize);
    this.setState({
      pageSize,
    })
    this.props.onSubmit({ current, pageSize }) // 给父组件传值 实现更改数据
  }


  render() {
    const { getFieldDecorator } = this.props.form;
    // const { dataSource1,name } = this.props
    // console.log(this.props,'v')
    return (
      <div>
        <Button
          // disabled={this.state.showModel4}
          // className={styles.buttonb}
          type='primary'
          icon={this.props.icons}
          size="small"
          onClick={() => this.handleOpen('showModel1')}>
          {this.props.name}
        </Button>
        <div></div>
        <Modal
          style={{ top: 60 }}
          width={'calc( 70vw)'}
          className={styles.overa}
          title={`当前问题:${this.props.title}`}
          visible={this.state.showModel1}
          footer={null}
          onCancel={() => {
            setTimeout(() => {
              this.setState({
                showModel4: false
              })
            }, 100)

            this.setState({
              showModel1: false
            })
          }}
          onOk={() => { // 确定方法不开出去
            this.setState({
              showModel1: false
            })
          }}
        >
          <Form layout="inline" style={{ paddingBottom: 20 }}>
            <FormItem style={{ marginLeft: 20 }}>

              <Select
                defaultValue={this.state.numberRadio}
                style={{ width: 160 }}
                onChange={this.handleChange}
              >
                <Option value='1'>搜索问题</Option>
                <Option value='2'>搜索答案</Option>
              </Select>
            </FormItem>
            <FormItem >
              {getFieldDecorator('businessName', {
                initialValue: '',
              })(
                <Search
                  placeholder="请输入搜索内容"
                  onSearch={value => {
                    this.props.onFrom(value)
                  }}
                  style={{ width: 320 }}
                />
              )}


            </FormItem>
          </Form>

          <Spin spinning={this.props.logins}>
            <Table
              className={styles.over}
              //  bordered
              columns={this.props.columns1}
              dataSource={this.props.dataSource1}//数据
              pagination={{  // 分页
                total: this.props.total1, // 数据总数量
                pageSize: this.state.pageSize,  // 显示几条一页
                defaultPageSize: 1, // 默认显示几条一页
                showSizeChanger: true,  // 是否显示可以设置几条一页的选项
                onChange: this.onChangeA,
                onShowSizeChange: this.onShowSizeChangeA
              }}
            />
          </Spin>
        </Modal>
      </div>
    )
  }
}

// export default PopoutRelevance
export default connect(({ user }) => ({ // 全局数据
  currentUser: user.currentUser,
}))(Form.create()(PopoutRelevance));
